<?php
class TixianjinAction extends BaseAction {
 
 
	function index() {
	if(isset($_REQUEST['mallid'])){$_SESSION['mallid']=$_REQUEST['mallid'];  }
	//$this->shenqintixian();
		$this->display();
		}
	function shenqintixian()
	{ 
	     /*'商城名称', name: 'mallname', 
		?'收益比例', name: 'sybl', 
        '购物金额', name: 'sales'
	    '总收益', name: 'commission', 
        '购物收益', name: 'gusy', 
		'业务收益', name: 'ywsy', 
		'分红收益', name: 'fhsy', 
		'商城人气', name: 'scrq', 
	    '商城标志', name: 'mallimg',
		'去购物赚收益', name: 'mallurl',
	    '业务链接', name: 'ywurl',
	  */
	   $table1=array();
	  $j=0;

	 if(isset($_SESSION['mallid'])){
	    $usertixian=$this->mall_order->field('mall_name')->where("adid='".$_SESSION['mallid']."'AND uid='".$this->uid."'")->select();
	      $table1[$j]['mallname']=$usertixian[0]['mall_name'];
		  $table1[$j]['sales']=round($this->mall_order->field('sales')->where("adid='".$_SESSION['mallid']."'AND uid='".$this->uid."'")->sum('sales'),2);
		  $table1[$j]['commission']=round($this->mall_order->field('commission')->where("adid='".$_SESSION['mallid']."'AND uid='".$this->uid."'")->sum('commission'),2);
	      $table1[$j]['gusy']=round($table1[$j]['commission']*0.2,2);
		  $table1[$j]['ywsy']=round($table1[$j]['commission']*0.3,2);
		  $table1[$j]['fhsy']=round($table1[$j]['commission']*0.1,2);
		    $table1[$j]['txzje']=round($table1[$j]['gusy']+$table1[$j]['gusy']+$table1[$j]['fhsy'],2);
		   $table1[$j]['mallimg']="<img src='".$val1['img']."'/>";
	      $table1[$j]['mallurl']="<a href='".$val1['url'].$this->uid."'>去购物</a>";
		  $table1[$j]['tixianjin']="<a href='".$_ROOT."/index.php/Tixianjin/tixianqueren?money=".$table1[$j]['txzje']."'>确认申请</a>";
		  $j++;
		 unset($_SESSION['mallid']);
		  
		//  print_r($this->malldata);
		 $data="{Rows:".json_encode($table1).",Total:".count($table1)."}";
		
	     $this->ajaxReturn($data,"","");
	 
	 }else{
	  foreach($this->getdbleveldata($_POST['id']) as $ke => $val){
	    $val1=$this->object2array($val);
	      $table1[$j]['mallname']=$val1['name'];
		  $table1[$j]['sybl']=0.7;
		  $table1[$j]['sales']=round($this->mall_order->field('sales')->where("adid='".$ke."'AND uid='".$this->uid."'")->sum('sales'),2);
		  $table1[$j]['commission']=round($this->mall_order->field('commission')->where("adid='".$ke."'AND uid='".$this->uid."'")->sum('commission'),2);
	      $table1[$j]['gusy']=round($table1[$j]['commission']*0.2,2);
		  $table1[$j]['ywsy']=round($table1[$j]['commission']*0.3,2);
		  $table1[$j]['fhsy']=round($table1[$j]['commission']*0.1,2);
		    $table1[$j]['txzje']=round($table1[$j]['gusy']+$table1[$j]['gusy']+$table1[$j]['fhsy'],2);
		   $table1[$j]['mallimg']="<img src='".$val1['img']."'/>";
	      $table1[$j]['mallurl']="<a href='".$val1['url'].$this->uid."'>去购物</a>";
		  $table1[$j]['tixianjin']="<a href='".$_ROOT."/index.php/Tixianjin/tixianqueren?money=".$table1[$j]['txzje']."'>确认申请</a>";
		  $j++;
		 } 
		  
		//  print_r($this->malldata);
		 $data="{Rows:".json_encode($table1).",Total:".count($table1)."}";
		
	     $this->ajaxReturn($data,"","");
	   }
	 
	
	}
 function tixianqueren(){
 if($this->uid==0){ $this->assign("sqzt","会员您好，您还没有登录，不能申请提现，如果有问题可随时咨询企业QQ:800048361");
 }else{
 if($_REQUEST['money']==0){
  $this->assign("sqzt","会员您好，您的提现申请失败，申请提现金额不能为0，如果有问题可随时咨询企业QQ:800048361");
 }else{
   $tixian=D("Tixian");
   $tixian1['uid']=$this->uid;
   $tixian1['money']=$_REQUEST['money'];
   $tixian1['money2']=0;
   
   if($tixian->add($tixian1)){
   $this->assign("sqzt","会员您好，您的提现申请成功，我们会在30天之内处理您的提现申请，请您耐心等候，如果有问题可随时咨询企业QQ:800048361");
   }else{
      $this->assign("sqzt","会员您好，您的提现申请失败，如果有问题可随时咨询企业QQ:800048361");
   }}}
 $this->display();
 }
}